<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>编辑概况</title>
    <script type="text/javascript" src="assets/dwz/ui/uploadify/scripts/jquery.uploadify.js"></script>
    <script type="text/javascript">
        $(function(){
            //初始化uploadify 用于word上传
            $("#uploadFile").uploadify({
                'swf' : 'assets/dwz/ui/uploadify/scripts/uploadify.swf',//上传的flash文件,必用
                'uploader' : 'community_image_service',//上传的请求URL
                'method' : "get",//请求方式
                'fileObjName' : 'fileName',//与后台Action中file属性一样
                'formData' : {
                    'uploadUrl' : 'hangzhou/talent'
                },//附带值，参数
                'auto' : true,//自动上传
                'multi' : false,//是否为多文件上传
                'buttonImage':'assets/dwz/ui/uploadify/img/upload.png',
                'uploadLimit' : 100000,//一次可以上传多少个文件
                'fileSizeLimit' : '100000KB',//单个文件上传最大值
                'queueSizeLimit' : 100,//最多上传个数
                'successTimeout' : 99999,//上传超时时间
                'rollover' : true,
                'dataType':'json',
                'removeCompleted' : true,//上传完成后是否自动隐藏进度条
                onUploadSuccess : function(file,//每个文件上传完成后都会调用一次，其中data为，相应信息，file为上传文件信息,response只有两个值true or false
                                           data, response) {
                    if( data == null ){
                        alertErrorMessage("上传图片失败");
                        return;
                    }
                    alertOkMessage( "上传成功！" );
                    $(".edit-survey-form img").attr("src",data);
                    $(".edit-survey-form input[name='imageUrl']").val(data);
                },
                onError : function() {
                    alertErrorMessage("上传失败");
                }
            });
        })

        //提交表单校验
        function checkEditSurvey(){
            var id = "";
            $(".edit-survey-form").find( "input[name='blockIds']:checked").each(function(i,j){
                id += $(j).val() + ",";
            })
            if( id == "" ){
                alertErrorMessage("请选择小区");
                return false;
            }
            id = id.substring( 0,id.length - 1 );
            var imageUrl = $(".edit-survey-form").find( "input[name='imageUrl']").val();
            if( imageUrl == null || imageUrl == "" || imageUrl == "http://jielan.oss-cn-hangzhou.aliyuncs.com/qyh2%2Fimages%2Fapp_cover%2Fqy_yidongxiaoyuan.jpg" ){
                alertMsg.warn('请上传封面！')
                return false;
            }

            $(".edit-survey-form").find( "input[name='blockId']").val( id );
            $(".edit_community_survey_form").submit();
        }

        //全选/取消全选
        function checkedAllBlock(){
            var objChecked = $( ".edit-survey-form" ).find( "input[name='checkedAll']" ).attr( "checked" );
            if( objChecked == "checked" ){
                $(".edit-survey-form").find( "input[name='blockIds']").each(function(i,j){
                    $(j).attr( "checked","checked" );
                })
            }else{
                $(".edit-survey-form").find( "input[name='blockIds']").each(function(i,j){
                    $(j).removeAttr( "checked" );
                })
            }
        }

        //错误提示
        function alertErrorMessage(word){
            alertMsg.error(word);
        }

        //成功提示
        function alertOkMessage(word){
            alertMsg.correct(word);
        }

        //删除图片
        $(".edit-survey-form .delete-this-pic").click(function () {
            $(".edit-survey-form img").attr("src","http://jielan.oss-cn-hangzhou.aliyuncs.com/qyh2%2Fimages%2Fapp_cover%2Fqy_yidongxiaoyuan.jpg");
            $(".edit-survey-form input[name='imageUrl']").val("");
        })

    </script>
</head>
<body>
<div class="page unitBox">
    <form method="post" action="save_edit_community_survey" class="pageForm required-validate edit_community_survey_form" onsubmit="return validateCallback(this, dialogAjaxDone)" novalidate="novalidate">
        <div class="pageContent">
            <div class="pageFormContent edit-survey-form" layouth="97">
                <dl style="height: 110px;">
                    <dt>社区封面：</dt>
                    <dd style="position:relative;">
                        <img src="${image.imageUrl}" width="120px;" height="80px;"/>
                        <input type="file" name="file" id="uploadFile" />
                        <input type="hidden" name="imageUrl" value="${image.imageUrl}"/>
                        <a style="background: rgba(0,0,0,0.5);display:block;position:absolute;top:0;left:86px;padding:5px;text-align: center;color:#fff;" class="delete-this-pic">删除</a>
                    </dd>
                </dl>
                <dl style="height: 80px;">
                    <dt>介绍：</dt>
                    <dd>
                        <textarea name="communityContent" placeholder="最多只能输入500个汉字" cols="25" rows="4" class="required">${survey.communityContent}</textarea>
                    </dd>
                </dl>
                <dl style="height: 80px;">
                    <dt>备注：</dt>
                    <dd>
                        <textarea name="remark" placeholder="最多只能输入500个汉字" cols="25" rows="4">${survey.remark}</textarea>
                    </dd>
                </dl>
                <dl style="height: auto;">
                    <dt>所属小区：</dt>
                    <dd>
                        <input type="hidden" name="blockId"/>
                        <input type="checkbox" name="checkedAll" onclick="checkedAllBlock();"/>全选<br>
                        <c:forEach var="block" items="${blocks}">
                            <input type="checkbox" value="${block.id}" name="blockIds" checked="checked"/>${block.blockName}<br>
                        </c:forEach>
                        <c:forEach var="blockNot" items="${blockNots}">
                            <input type="checkbox" value="${blockNot.id}" name="blockIds" />${blockNot.blockName}<br>
                        </c:forEach>
                    </dd>
                </dl>
            </div>
            <input type="hidden" value="${survey.id}" name="id"/>
            <input type="hidden" value="${survey.parentId}" name="parentId"/>
            <div class="formBar">
                <ul>
                    <li><div class="buttonActive"><div class="buttonContent"><button type="button" onclick="return checkEditSurvey();">保存</button></div></div></li>
                    <li><div class="button"><div class="buttonContent"><button class="close" type="button">关闭</button></div></div></li>
                </ul>
            </div>

        </div>
    </form>
</div>
</body>
</html>
